<?php

namespace app\api\middleware;

use dengje\jwt\facade\JWTAuth;

class Check
{
    public function handle($request, \Closure $next)
    {
        try {
            $payload = JWTAuth::auth();
        } catch (\Exception $e) { // 捕获token过期
            return error('身份信息已过期！', 401);
            //throw new \think\exception\HttpException(401, '无效 token');
        }
        $uid = $payload['uid'];
        $request->uid = $uid;

        return $next($request);
    }
}
